package 基础语法;

import java.util.Scanner;

public class 字符串 {
    public static void main(String[] args) {
        String s = "aaa";
        String s1 = new String();
        System.out.println("_" + s1 + "_");
        s1 = new String("aa");

        char[] c = { 'a', 'z' };
        s1 = new String(c);
        c[0] = 'A';
        s1 = new String(c);

        byte[] b = { 12, 12, 23 };
        s1 = new String(b);

        String s2 = "abc";
        String s3 = "abc";
        // 注意s2,s3此时指向同一个地址,"abc"存于堆内存的“串空间”中
        // https://www.bilibili.com/video/BV17F411T7Ao?spm_id_from=333.788.player.switch&vd_source=c00805f5ab54eeaa2b3bb0b0a1633967&p=98
        String s4 = new String("abc");
        String s5 = new String("abc");
        // s4、s5指向各自的地址，两个字符串就是存在堆内存中

        System.out.println(s2 == s4);// false,对于引用类型，比较的是地址值。基础类型比较的是数据值

        System.out.println(s2.equals(s4));// true
        s3 = "Abc";

        System.out.println(s4.equalsIgnoreCase(s3));// true


        for (int i = 0; i < s1.length(); i++) {
            System.out.println(s1.charAt(i));
        }

        String kkkk="0123456789";
        System.out.println(kkkk.substring(1));
        System.out.println(kkkk.substring(0,2));
        System.out.println(kkkk.replace("9", "-"));
        System.out.println(kkkk.substring( 1).replace("9", "--").concat("ss"));

        String j="abc";
        String k="a"+"b"+"c";//编译阶段生成.class文件时优化为"abc"
        System.out.println(j==k);
        String l="ab";
        String m=l+"c";//有变量 参与，底层是使用StringBuilder实现的拼接，然后调用其toString方法返回一个new出来的String对象，
        System.out.println(m==j);        


        Scanner sc = new Scanner(System.in);
        String abc = sc.next();
        System.out.println(abc == s2);// false

    }

}
